Convert Kilometers to Miles

Theory:

1 kilometer is equal to 0.621371 miles.

Python Code:

def kilometers_to_miles(kilometers):
    return kilometers * 0.621371

# Taking input for kilometers and converting them to miles
def convert_and_display_kilometers_to_miles():
    kilometers = float(input("Enter the distance in kilometers: "))
    miles = kilometers_to_miles(kilometers)
    print("Distance in miles:", miles)

convert_and_display_kilometers_to_miles()

Example Output 1:

Enter the distance in kilometers: 10

Distance in miles: 6.21371

Example Output 2:

Enter the distance in kilometers: 25

Distance in miles: 15.534275

Code Explanation:

The function kilometers_to_miles(kilometers) converts kilometers to miles using the conversion factor.

The function convert_and_display_kilometers_to_miles() takes input for kilometers, converts them to miles using the aforementioned function, and displays the result.